home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / www / library / implemen / htutils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  9.1 KB  |  350 lines

  1. /*                                                    Utitlity macros for the W3 code library
  2.                                   MACROS FOR GENERAL USE
  3.                                              
  4.    Generates: HTUtils.h
  5.    
  6.    See also: the system dependent file "tcp.h"
  7.    
  8.  */
  9.  
  10. #ifndef DEBUG
  11. #define DEBUG   /* Noone ever turns this off as trace is too important */
  12. #endif          /* Keeep option for really small memory applications tho */
  13.                 
  14. #ifndef HTUTILS_H
  15. #define HTUTILS_H
  16.  
  17. #ifdef _WINDOWS                         /* SCW */
  18. #include "windef.h"
  19. #define BOOLEAN_DEFINED
  20. #endif
  21.  
  22. #ifdef SHORT_NAMES
  23. #define WWW_TraceFlag HTTrFlag
  24. #endif
  25.  
  26. /*
  27.  
  28. Debug message control.
  29.  
  30.  */
  31. #ifndef STDIO_H
  32. #include <stdio.h>
  33. #define STDIO_H
  34. #endif
  35.  
  36. #ifdef DEBUG
  37. #ifndef RELEASE
  38. #define TRACE (WWW_TraceFlag)
  39. #endif /* RELEASE */
  40. #define PROGRESS(str) printf(str)
  41. #ifndef RELEASE
  42.     extern int WWW_TraceFlag;
  43. #endif /* RELEASE */
  44. #else
  45. #ifndef RELEASE
  46. #define TRACE 0
  47. #endif /* RELEASE */
  48. #define PROGRESS(str) /* nothing for now */
  49. #endif
  50.  
  51. #ifndef RELEASE
  52. #define CTRACE if(TRACE)fprintf
  53. #endif /* RELEASE */
  54. #define tfp stderr
  55.  
  56. /*
  57.  
  58.   ERROR TYPE
  59.   
  60.    This is passed back when streams are aborted. It might be nice to have some structure
  61.    of error messages, numbers, and recursive pointers to reasons. Curently this is a
  62.    placeholder for something more sophisticated.
  63.    
  64.  */
  65. typedef void * HTError;                 /* Unused at present -- best definition? */
  66.  
  67. /*
  68.  
  69. Standard C library for malloc() etc
  70.  
  71.  */
  72. #ifdef vax
  73. #ifdef unix
  74. #define ultrix  /* Assume vax+unix=ultrix */
  75. #endif
  76. #endif
  77.  
  78. #ifndef VMS
  79. #ifndef ultrix
  80. #ifdef NeXT
  81. #include <libc.h>       /* NeXT */
  82. #endif
  83. #ifndef MACH /* Vincent.Cate@furmint.nectar.cs.cmu.edu */
  84. #include <stdlib.h>     /* ANSI */
  85. #endif
  86. #else /* ultrix */
  87. #include <malloc.h>
  88. #include <memory.h>
  89. #include <stdio.h>
  90. #include <stdlib.h>   /* ANSI */   /* BSN */
  91. #endif
  92.  
  93. #else   /* VMS */
  94. #include <stdio.h>
  95. #include <ctype.h>
  96. #endif
  97.  
  98. /*
  99.  
  100. Macros for declarations
  101.  
  102.  */
  103. #define PUBLIC                  /* Accessible outside this module     */
  104. #define PRIVATE static          /* Accessible only within this module */
  105.  
  106. #ifdef MSDOS
  107. #define CONST const             /* "const" only exists in STDC */
  108. #define NOPARAMS (void)
  109. #define PARAMS(parameter_list) parameter_list
  110. #define NOARGS (void)
  111. #define ARGS1(t,a) \
  112.         (t a)
  113. #define ARGS2(t,a,u,b) \
  114.         (t a, u b)
  115. #define ARGS3(t,a,u,b,v,c) \
  116.         (t a, u b, v c)
  117. #define ARGS4(t,a,u,b,v,c,w,d) \
  118.         (t a, u b, v c, w d)
  119. #define ARGS5(t,a,u,b,v,c,w,d,x,e) \
  120.         (t a, u b, v c, w d, x e)
  121. #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) \
  122.         (t a, u b, v c, w d, x e, y f)
  123. #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) \
  124.         (t a, u b, v c, w d, x e, y f, z g)
  125. #define ARGS8(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h) \
  126.         (t a, u b, v c, w d, x e, y f, z g, s h)
  127. #define ARGS9(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i) \
  128.         (t a, u b, v c, w d, x e, y f, z g, s h, r i)
  129. #define ARGS10(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i,q,j) \
  130.         (t a, u b, v c, w d, x e, y f, z g, s h, r i, q j)
  131. #else
  132.  
  133. #ifdef __STDC__
  134. #define CONST const             /* "const" only exists in STDC */
  135. #define NOPARAMS (void)
  136. #define PARAMS(parameter_list) parameter_list
  137. #define NOARGS (void)
  138. #define ARGS1(t,a) \
  139.         (t a)
  140. #define ARGS2(t,a,u,b) \
  141.         (t a, u b)
  142. #define ARGS3(t,a,u,b,v,c) \
  143.         (t a, u b, v c)
  144. #define ARGS4(t,a,u,b,v,c,w,d) \
  145.         (t a, u b, v c, w d)
  146. #define ARGS5(t,a,u,b,v,c,w,d,x,e) \
  147.         (t a, u b, v c, w d, x e)
  148. #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) \
  149.         (t a, u b, v c, w d, x e, y f)
  150. #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) \
  151.         (t a, u b, v c, w d, x e, y f, z g)
  152. #define ARGS8(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h) \
  153.         (t a, u b, v c, w d, x e, y f, z g, s h)
  154. #define ARGS9(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i) \
  155.         (t a, u b, v c, w d, x e, y f, z g, s h, r i)
  156. #define ARGS10(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i,q,j) \
  157.         (t a, u b, v c, w d, x e, y f, z g, s h, r i, q j)
  158.  
  159. #else  /* not ANSI */
  160.  
  161. #ifndef _WINDOWS
  162. #define CONST
  163. #endif
  164. #define NOPARAMS ()
  165. #define PARAMS(parameter_list) ()
  166. #define NOARGS ()
  167. #define ARGS1(t,a) (a) \
  168.         t a;
  169. #define ARGS2(t,a,u,b) (a,b) \
  170.         t a; u b;
  171. #define ARGS3(t,a,u,b,v,c) (a,b,c) \
  172.         t a; u b; v c;
  173. #define ARGS4(t,a,u,b,v,c,w,d) (a,b,c,d) \
  174.         t a; u b; v c; w d;
  175. #define ARGS5(t,a,u,b,v,c,w,d,x,e) (a,b,c,d,e) \
  176.         t a; u b; v c; w d; x e;
  177. #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) (a,b,c,d,e,f) \
  178.         t a; u b; v c; w d; x e; y f;
  179. #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) (a,b,c,d,e,f,g) \
  180.         t a; u b; v c; w d; x e; y f; z g;
  181. #define ARGS8(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h) (a,b,c,d,e,f,g,h) \
  182.         t a; u b; v c; w d; x e; y f; z g; s h;
  183. #define ARGS9(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i) (a,b,c,d,e,f,g,h,i) \
  184.         t a; u b; v c; w d; x e; y f; z g; s h; r i;
  185. #define ARGS10(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i,q,j) (a,b,c,d,e,f,g,h,i,j) \
  186.         t a; u b; v c; w d; x e; y f; z g; s h; r i; q j;
  187.  
  188.  
  189. #endif /* __STDC__ (ANSI) */
  190. #endif /* MSDOS */
  191.  
  192. #ifndef NULL
  193. #define NULL ((void *)0)
  194. #endif
  195.  
  196. /*
  197.  
  198. Booleans
  199.  
  200.  */
  201. /* Note: GOOD and BAD are already defined (differently) on RS6000 aix */
  202. /* #define GOOD(status) ((status)38;1)   VMS style status: test bit 0         */
  203. /* #define BAD(status)  (!GOOD(status))  Bit 0 set if OK, otherwise clear   */
  204.  
  205. #ifndef _WINDOWS
  206. #ifndef BOOLEAN_DEFINED
  207.     typedef char    BOOLEAN;                /* Logical value */
  208. #ifndef CURSES
  209. #ifndef TRUE
  210. #define TRUE    (BOOLEAN)1
  211. #define FALSE   (BOOLEAN)0
  212. #endif
  213. #endif   /*  CURSES  */
  214. #endif   /* _WINDOWS */
  215. #define BOOLEAN_DEFINED
  216. #endif
  217.  
  218. #ifndef BOOL
  219. #define BOOL BOOLEAN
  220. #endif
  221. #ifndef YES
  222. #define YES (BOOLEAN)1
  223. #define NO (BOOLEAN)0
  224. #endif
  225.  
  226. #ifndef MIN
  227. #define MIN(a,b) ((a) <= (b) ? (a) : (b))
  228. #define MAX(a,b) ((a) >= (b) ? (a) : (b))
  229. #endif
  230.  
  231. #define TCP_PORT 80     /* Allocated to http by Jon Postel/ISI 24-Jan-92 */
  232. #define OLD_TCP_PORT 2784       /* Try the old one if no answer on 80 */
  233. #define DNP_OBJ 80      /* This one doesn't look busy, but we must check */
  234.                         /* That one was for decnet */
  235.  
  236. /*      Inline Function WHITE: Is character c white space? */
  237. /*      For speed, include all control characters */
  238.  
  239. #define WHITE(c) (((unsigned char)(TOASCII(c))) <= 32)
  240.  
  241.  
  242. /*
  243.  
  244. Sucess (>=0) and failure (<0) codes
  245.  
  246.  */
  247.  
  248. #define HT_LOADED 29999                 /* Instead of a socket */
  249. #define HT_REDIRECTION_ON_FLY 29998     /* Redo the retrieve with a new URL */
  250.  
  251. #define HT_OK           0               /* Generic success*/
  252.  
  253. #define HT_NO_ACCESS    -10             /* Access not available */
  254. #define HT_FORBIDDEN    -11             /* Access forbidden */
  255. #define HT_INTERNAL     -12             /* Weird -- should never happen. */
  256. #define HT_BAD_EOF      -12             /* Premature EOF */
  257.  
  258.  
  259. #include "HTString.h"   /* String utilities */
  260.  
  261. #ifdef __STDC__
  262. #include <stdarg.h>
  263. #else
  264. #include <varargs.h>
  265. #endif
  266.  
  267. #ifdef CURSES
  268.         /* htbrowse.c; */
  269. #ifdef ULTRIX      /* or DECSTATION */
  270. #include <cursesX.h>    /* Extended curses under X. Only decent one :lou. */
  271. #else
  272. #include <curses.h>
  273. #endif /* ULTRIX */
  274.         extern        WINDOW  *w_top, *w_text, *w_prompt;
  275.         extern        void    user_message PARAMS((const char *fmt, ...));
  276.         extern        void    prompt_set PARAMS((CONST char * msg));
  277.         extern        void    prompt_count PARAMS((long kb));
  278. #else
  279. #define user_message printf
  280. #endif
  281.  
  282. /*
  283.  
  284. Out Of Memory checking for malloc() return:
  285.  
  286.  */
  287. #ifndef __FILE__
  288. #define __FILE__ ""
  289. #define __LINE__ ""
  290. #endif
  291.  
  292. #ifndef MSDOS
  293. #define outofmem(file, func) \
  294.  { fprintf(stderr, "%s %s: out of memory.\nProgram aborted.\n", file, func); \
  295.   exit(1);}
  296. #else
  297. #define outofmem(file, func) \
  298.  { fprintf(stderr, "%s %s: out of memory.\n", file, func);\
  299.    fprintf(stderr, "WWW htutils.h exit(1); denied by doslynx.\n");\
  300.    fprintf(stderr, "Consider leaving the application.\n"); }
  301. #endif /* MSDOS */
  302. /* extern void outofmem PARAMS((const char *fname, const char *func)); */
  303.  
  304.  
  305. /*
  306.  
  307.   WHO PUT THESE IN AND WHAT ARE THEY ANYWAY?
  308.   
  309.  */
  310. #ifdef THEY_WILL_BE_REMOVED
  311. extern void msg_init PARAMS((int height));
  312. extern void msg_printf PARAMS((int y, const char *fmt, ...));
  313. extern void msg_exit PARAMS((int wait_for_key));
  314. #endif
  315.  
  316. /*
  317.  
  318. Upper- and Lowercase macros
  319.  
  320.    The problem here is that toupper(x) is not defined officially unless isupper(x) is.
  321.    These macros are CERTAINLY needed on #if defined(pyr) || define(mips) or BDSI
  322.    platforms. For safefy, we make them mandatory.
  323.    
  324.  */
  325. #include <ctype.h>
  326.  
  327. #ifndef TOLOWER
  328.   /* Pyramid and Mips can't uppercase non-alpha */
  329. #define TOLOWER(c) (isupper(c) ? tolower(c) : (c))
  330. #define TOUPPER(c) (islower(c) ? toupper(c) : (c))
  331. #endif /* ndef TOLOWER */
  332.  
  333. /*
  334.  
  335. The local equivalents of CR and LF
  336.  
  337.    We can check for these after net ascii text has been converted to the local
  338.    representation. Similarly, we include them in strings to be sent as net ascii after
  339.    translation.
  340.    
  341.  */
  342. #define LF   FROMASCII('\012')  /* ASCII line feed LOCAL EQUIVALENT */
  343. #define CR   FROMASCII('\015')  /* Will be converted to ^M for transmission */
  344.  
  345. #endif /* HTUTILS_H */
  346.  
  347. /*
  348.  
  349.    end of utilities */
  350.